home *** CD-ROM | disk | FTP | other *** search
- import java.awt.*;
- import java.applet.*;
-
- public class GraphicsApplet extends Applet {
- Font appFont;
-
- public void init() {
- appFont = new Font("Helvetica",Font.BOLD,14);
- }
- public void drawCenteredString(String s,
- Color color,
- Graphics g,
- Dimension r) {
- FontMetrics fm = g.getFontMetrics();
- int sWidth = fm.stringWidth(s);
- int sHeight = fm.getHeight();
- g.setColor(color);
- g.drawString(s,(r.width - sWidth)/2, (r.height - sHeight)/2);
- }
- public void paint(Graphics g) {
- Dimension r = size();
- g.setFont(appFont);
- drawCenteredString("Graphics",Color.white,g,r);
- }
- }
-